refactor(core): remove core.lua and adopt services as shared primitives#360
refactor(core): remove core.lua and adopt services as shared primitives#360jensenojs wants to merge 1 commit intosudo-tee:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the legacy opencode.core module and refactors core runtime behavior into a set of shared services/* primitives, updating UI/handler entrypoints and splitting the previously core-centric unit specs into service-focused test files.
Changes:
- Introduce
opencode.services.session_runtime,opencode.services.messaging, andopencode.services.agent_modelas the new shared primitives and deletelua/opencode/core.lua. - Rewire UI entrypoints and command handlers to call services instead of
opencode.core. - Split/refactor unit tests to align with the new service boundaries and add boundary documentation (
AGENTS.md).
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/services_spec_support.lua | Adds shared test helpers for mocking api_client and snapshot/restore of state/vim globals. |
| tests/unit/services_session_runtime_spec.lua | Migrates legacy core specs to session_runtime-focused tests; adds a setup idempotence test. |
| tests/unit/services_messaging_spec.lua | Adds messaging service unit tests (send flow + state updates). |
| tests/unit/services_agent_model_spec.lua | Adds agent_model service unit tests (mode/model initialization & restore). |
| tests/unit/hooks_spec.lua | Updates hook subscriptions to point at session_runtime service handlers. |
| tests/unit/commands_handlers_spec.lua | Updates tracked modules list to include services and remove core. |
| tests/unit/api_spec.lua | Updates API tests for new services wiring and adds a submit-input routing test. |
| lua/opencode/ui/session_picker.lua | Replaces core session switching/creation calls with session_runtime equivalents. |
| lua/opencode/ui/renderer.lua | Routes model restore-through-messages via services.agent_model. |
| lua/opencode/ui/input_window.lua | Routes submit to services.messaging.send_message. |
| lua/opencode/ui/history_picker.lua | Replaces core open call with session_runtime.open({ focus = 'input' }). |
| lua/opencode/ui/autocmds.lua | Routes cwd change handling through session_runtime.handle_directory_change. |
| lua/opencode/services/session_runtime.lua | New runtime/session orchestration service extracted from core. |
| lua/opencode/services/messaging.lua | New message send + after-run lifecycle service extracted from core. |
| lua/opencode/services/agent_model.lua | New model/mode/provider/variant service extracted from core. |
| lua/opencode/services/AGENTS.md | Documents the services boundary and invariants vs handlers. |
| lua/opencode/quick_chat.lua | Replaces core dependencies with services for session creation and model init. |
| lua/opencode/init.lua | Moves setup/subscriptions out of core into init and adds setup idempotence guard. |
| lua/opencode/core.lua | Deletes the legacy core module (replaced by services). |
| lua/opencode/commands/handlers/workflow.lua | Updates workflow actions to use services (open/send/model init/image paste). |
| lua/opencode/commands/handlers/window.lua | Updates window actions (open/cancel/toggle) to use session_runtime. |
| lua/opencode/commands/handlers/session.lua | Updates session actions to use session_runtime + agent_model. |
| lua/opencode/commands/handlers/diff.lua | Updates diff open helper to use session_runtime open/open_if_closed. |
| lua/opencode/commands/handlers/agent.lua | Updates agent actions to use agent_model service. |
| lua/opencode/commands/handlers/AGENTS.md | Aligns handler boundary doc with new services layer and debt list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4b21675 to
4008866
Compare
test: split legacy core_spec into service-focused specs chore(docs): align handlers/services AGENTS boundaries
4008866 to
b271725
Compare
|
This PR is just a beginning; it doesn't actually clean up the code (call chain). I'll add an analysis and explanation later. The division of phases in this stage is quite rough and not very instructive, but I still hope you can review this architecture diagram or the vision here. I believe this approach is key to improving maintainability in the future. Currently, the hierarchy of dependencies between Lua modules is very messy, so splitting the core merely shifts the focus of the problem without truly solving it. I'm working on a small script to trace the call chains between this plugin's modules. The specific design of the call flow is a topic open for further discussion (defined by JSON). We can use that little tool to see the gap between the current state of the code and the expected outcome, as well as the extent of reference relationship cleanup under each diff. In a way, I think it might be the endpoint of architectural code cleanup? |
|
using #361 |
test: split legacy core_spec into service-focused specs
chore(docs): align handlers/services AGENTS boundaries